<?php $search_type_value_array=  array('expert' => '找行家','story' => '找事做','group' => '找小组');
if (empty($search_type)) {
	$search_type_value = '找行家';
} else {
	$search_type_value = $search_type_value_array[$search_type];
}
?>
<div id="header">
	<div class="header_content">
		<a href="<?php echo site_url();?>"><img class="logo" src="/img/logo.png" /></a>
		<form class="search_box" method="get" action="<?php echo site_url("search");?>" onsubmit="return is_search_box_empty(this);">
			<div class="search_type">
				<div class="arrow_down">&nbsp;</div>
				<div class="type"><?php echo $search_type_value;?></div>
				<ul class="hide">
					<li class="<?php echo $search_type_value == '找行家' ? 'hide' : ''?>" search_type="expert">找行家</li>
					<li class="<?php echo $search_type_value == '找事做' ? 'hide' : ''?>" search_type="story">找事做</li>
					<li class="<?php echo $search_type_value == '找小组' ? 'hide' : ''?>" search_type="group">找小组</li>
				</ul>
				<input type="hidden" name="search_type" value="<?php echo empty($search_type) ? 'expert' : $search_type?>" id="search_category_type"/>
			</div>
			<div class="search_value">
				<input type="text" name="key" class="key" value="" placeholder="输入搜索关键字"/>
			</div>
			<div class="search_submit">
				<input type="submit" class="submit" value="搜索"/>
			</div>
		</form>
		<a class="emergency_pub" href="<?php echo site_url("story/create")?>"></a>
		<div class="clear"></div>
	</div>
	<script>
		$('.header_content').find('.search_box').find('.search_type').find('li').click(function(event){
			var $this = $(this);
			var $parent = $this.parent();
			$parent.find('li').removeClass('hide');
			var search_type = $this.attr('search_type');
			var type_select = $('.header_content').find('.search_box').find('.search_type').find('.type');
			switch (search_type) {
			case 'expert':
				type_select.text('找行家');
				$parent.find('li').eq(0).addClass('hide');
				break;
			case 'story':
				type_select.text('找事做');
				$parent.find('li').eq(1).addClass('hide');
				break;
			case 'group':
				type_select.text('找小组');
				$parent.find('li').eq(2).addClass('hide');
				break;
			}
			$('#search_category_type').val(search_type);
			$this.parent().hide();
			event.stopPropagation();
		});
		$('.header_content').find('.search_box').find('.arrow_down, .type').click(function(event){
			$(this).parent().find('ul').toggle();
			event.stopPropagation();
		});
		$(document).click(function(){
			$('.header_content').find('.search_box').find('.search_type').find('ul').hide();
		});

		function is_search_box_empty(src) {
			var search_text = $(src).find('.search_value').find('input').val();
			if ($.trim(search_text) == '') {
				window.location.reload();
				return false;
			} else {
				return true;
			}
		}
	</script>
</div>